package com.tank.dubbo.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.UnknownHostException;

/**
 * Created with IntelliJ IDEA.
 * User: SuQiEr
 * Date:2017/9/28
 * Time: 18:19
 * To change this template use File | Settings | File Templates.
 */
@Slf4j
@Service
public class DemoService2Impl implements DemoService2 {
    @Override
    public String sayHello(String name) {
//        Throwable t = new Throwable();
//        t.fillInStackTrace();
//        System.out.println(getStackTraceString(t));
      //  throw new NullPointerException();
       return "Hello " + name;
    }

    public static String getStackTraceString(Throwable tr) {
        if (tr == null) {
            return "";
        }
        Throwable t = tr;
        while (t != null) {
            if (t instanceof UnknownHostException) {
                return "";
            }
            t = t.getCause();
        }

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        tr.printStackTrace(pw);
        return sw.toString();
    }
}
